 /**
 * Description: PAD管理
 * @author:yueyemoyan
 * @since:1.0.0
 *
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-05-14   yueyemoyan       1.0.0     Initial
 */
package com.metro.activation.biz.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.github.pagehelper.PageInfo;
import com.metro.activation.biz.beans.vo.BizPadManagement;
import com.metro.activation.biz.service.inf.IBizPadManagementService;
import com.metro.activation.common.beans.constant.DicTypeEnum;
import com.metro.activation.common.utils.DicUtil;
import com.metro.activation.web.controller.BaseController;
import com.metro.core.annotation.BusinessDesc;
import com.metro.core.page.Page;
import com.metro.core.vo.JsonResult;
import com.metro.core.vo.QueryParams;
import com.metro.core.vo.ResultCode;
import com.metro.core.vo.inf.IResult;
 /**
 * PAD管理<br>
 *
 * @author:yueyemoyan
 * @since:1.0.0
 * @version [1.0.0, 2018-05-14]
 */
@Controller
@RequestMapping("/bizPadManagement")
public class BizPadManagementController extends BaseController {
    //菜单编码
    private static final String menuCode = "biz_pad_management";
    //模块描述
    private static final String MODULE_DESC = "PAD管理";
    @Autowired
    private IBizPadManagementService bizpadmanagementService;
    @Override
    protected String getViewDir() {
        return "biz/";
    }
    
    /**
     * 去查询PAD管理
     * 
     * @param bizpadmanagement PAD管理页面表单对象
     * @param page 分页配置
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "查询PAD管理列表")
    @RequiresPermissions(menuCode + ":view")
    @SuppressWarnings("all")
    @RequestMapping(value = "list", method = {RequestMethod.GET,RequestMethod.POST})
    public ModelAndView list(BizPadManagement bizpadmanagement) {
        ModelAndView mav = new ModelAndView();
        try {
        	mav.addObject("statusList", DicUtil.getLabelValueList(DicTypeEnum.PAD_STATUS));
            mav.setViewName(getView("bizpadmanagement_list"));
            mav.addObject("searchEntity", bizpadmanagement);
        } catch (Exception ex) {
            log.error("查询PAD管理出错", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
        }
        return mav;
    }

    /**
     * 查询PAD管理
     *
     * @param bizpadmanagement PAD管理页面表单对象
     * @param page 分页配置
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "查询PAD管理列表")
    @RequiresPermissions(menuCode + ":view")
    @SuppressWarnings("all")
    @RequestMapping(value = "dolist", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public JsonResult dolist(BizPadManagement bizpadmanagement, Page page, QueryParams<BizPadManagement> queryParams) {
        JsonResult jr = new JsonResult();
        try {
            queryParams.setPaging(page);
            queryParams.setEntity(bizpadmanagement);
            PageInfo<BizPadManagement> pageInfo = bizpadmanagementService.queryForPage(queryParams);
            jr.setData(pageInfo);
            jr.setResult(ResultCode.SUCCESS);
        } catch (Exception ex){
            log.error("查询PAD管理出错",ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }

    /**
     * 去新增PAD管理
     * 
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "去新增PAD管理")
    @RequiresPermissions(menuCode + ":add")
    @RequestMapping(value = "create")
    public ModelAndView createForm(Model model, HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        try {
            initCreateOrUpdateFrom(mav, "create");
        } catch (Exception ex) {
            log.error("去新增PAD管理出错", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
        }
        return mav;
    }
    
    /**
     * 初始化新增修改PAD管理所需参数
     * @author yueyemoyan
     */
    private void initCreateOrUpdateFrom(ModelAndView mav, String action){
        mav.addObject("action", action);
        mav.setViewName(getView("bizpadmanagement_form"));
    }
    
    /**
     * 新增PAD管理
     * 
     * @param entity PAD管理页面表单对象
     * @param request 请求对象
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "新增PAD管理")
    @RequiresPermissions(menuCode + ":add")
    @RequestMapping(value = "save", method = { RequestMethod.POST})
    @ResponseBody
    public JsonResult saveBizPadManagement(BizPadManagement entity, HttpServletRequest request) {
        JsonResult jr = new JsonResult();
        try {
            IResult res = bizpadmanagementService.save(entity);
            jr.setResult(res);
            log.debug("新增PAD管理成功【{}】", entity);
        } catch (Exception ex) {
            log.error("新增PAD管理出错", ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }

    /**
     * 删除PAD管理
     * 
     * @param id PAD管理页面表单对象唯一标识
     * @param request 请求对象
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "删除PAD管理")
    @RequiresPermissions(menuCode + ":delete")
    @RequestMapping(value = "delete/{id}", method = { RequestMethod.DELETE })
    @ResponseBody
    public JsonResult delete(@PathVariable String id, HttpServletRequest request){
        JsonResult jr = new JsonResult();
        try {
            log.debug("删除PAD管理id={}",id);
            IResult codeMsg = bizpadmanagementService.deleteByIds(id);
            jr.setResult(codeMsg);
        } catch (Exception ex) {
            log.error("删除PAD管理出错", ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }
    
    /**
     * 去修改PAD管理
     * 
     * @param id PAD管理页面表单对象唯一标识
     * @param request 请求对象
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "去修改PAD管理")
    @RequiresPermissions(menuCode + ":edit")
    @RequestMapping(value = "edit/{id}", method = { RequestMethod.GET})
    public ModelAndView updateForm(@PathVariable Long id, HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        try {
            BizPadManagement entity = bizpadmanagementService.getById(id);
            mav.addObject("entity", entity);
            initCreateOrUpdateFrom(mav,"edit");
        } catch (Exception ex) {
            log.error("去修改PAD管理", ex);
            mav.setView(new RedirectView("list"));
        }
        return mav;
    }

    /**
     * 修改PAD管理
     * 
     * @param entity PAD管理页面表单对象
     * @param request 请求对象
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "修改PAD管理")
    @RequiresPermissions(menuCode + ":edit")
    @RequestMapping(value = "update", method = { RequestMethod.POST})
    @ResponseBody
    public JsonResult updateBizPadManagement(BizPadManagement entity, HttpServletRequest request) {
        JsonResult jr = new JsonResult();
        try {
            IResult res = bizpadmanagementService.update(entity);
            jr.setResult(res);
            log.debug("修改PAD管理成功【{}】", entity);
        } catch (Exception ex) {
            log.error("修改PAD管理出错", ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }
    
    /**
     * 去查看PAD管理
     * 
     * @param id PAD管理页面表单对象唯一标识
     * @return 结果视图
     * @author yueyemoyan
     * @since [1.0.0]
     * @version [1.0.0, 2018-05-14]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "去查看PAD管理详情")
    @RequiresPermissions(menuCode + ":view")
    @RequestMapping(value = "info/{id}", method = { RequestMethod.GET })
    public ModelAndView info(@PathVariable Long id) {
        ModelAndView mav= new ModelAndView();
        try {
            mav.addObject("entity", bizpadmanagementService.getById(id));
            mav.setViewName(getView("bizpadmanagement_info"));
        } catch (Exception ex) {
            log.error("查看PAD管理出错", ex);
        }
        return mav;
        
    }
    
    /**
     * 注销
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "注销PAD")
    @RequestMapping(value="/cancel/{id}", method = { RequestMethod.POST })
    @RequiresPermissions(menuCode + ":cancel")
    @ResponseBody
    public JsonResult cancel(@PathVariable String id, HttpServletRequest request){
    	JsonResult jr = new JsonResult();
        try {
            log.debug("注销PADid={}",id);
            IResult codeMsg = bizpadmanagementService.cancelByIds(id);
            jr.setResult(codeMsg);
        } catch (Exception ex) {
            log.error("注销客户端出错", ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }
    
}
